<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
 <head>
  <meta http-equiv="content-type" content="text/html; charset=UTF-8">
  <title>Select MS SQL database</title>

 </head>
 <body><div class="manualnavbar" style="text-align: center;">
 <div class="prev" style="text-align: left; float: left;"><a href="function.mssql-rows-affected.html">mssql_rows_affected</a></div>
 <div class="next" style="text-align: right; float: right;"><a href="set.mysqlinfo.html">MySQL</a></div>
 <div class="up"><a href="ref.mssql.html">Mssql 函数</a></div>
 <div class="home"><a href="index.html">PHP Manual</a></div>
</div><hr /><div id="function.mssql-select-db" class="refentry">
 <div class="refnamediv">
  <h1 class="refname">mssql_select_db</h1>
  <p class="verinfo">(PHP 4, PHP 5, PECL odbtp &gt;= 1.1.1)</p><p class="refpurpose"><span class="refname">mssql_select_db</span> &mdash; <span class="dc-title">Select MS SQL database</span></p>

 </div>

 <div class="refsect1 description" id="refsect1-function.mssql-select-db-description">
  <h3 class="title">说明</h3>
  <div class="methodsynopsis dc-description">
   <span class="type">bool</span> <span class="methodname"><strong>mssql_select_db</strong></span>
    ( <span class="methodparam"><span class="type">string</span> <code class="parameter">$database_name</code></span>
   [, <span class="methodparam"><span class="type">resource</span> <code class="parameter">$link_identifier</code></span>
  ] )</div>

  <p class="para rdfs-comment">
   <span class="function"><strong>mssql_select_db()</strong></span> sets the current active
   database on the server that&#039;s associated with the specified link
   identifier.
  </p>
  <p class="para">
   Every subsequent call to <span class="function"><a href="function.mssql-query.html" class="function">mssql_query()</a></span> will be
   made on the active database.
  </p>
 </div>


 <div class="refsect1 parameters" id="refsect1-function.mssql-select-db-parameters">
  <h3 class="title">参数</h3>
  <p class="para">
   <dl>

    
     <dt>
<em><code class="parameter">database_name</code></em></dt>

     <dd>

      <p class="para">
       The database name.
      </p>
      <p class="para">
       To escape the name of a database that contains spaces, hyphens (&quot;-&quot;),
       or any other exceptional characters, the database name must be
       enclosed in brackets, as is shown in the example, below. This
       technique must also be applied when selecting a database name that is
       also a reserved word (such as <em>primary</em>).
      </p>
     </dd>

    
    
     <dt>
<em><code class="parameter">link_identifier</code></em></dt>

     <dd>

      <p class="para">
       A MS SQL link identifier, returned by
       <span class="function"><a href="function.mssql-connect.html" class="function">mssql_connect()</a></span> or
       <span class="function"><a href="function.mssql-pconnect.html" class="function">mssql_pconnect()</a></span>.
      </p>
      <p class="para">
       If no link identifier is specified, the last opened link is assumed.
       If no link is open, the function will try to establish a link as if
       <span class="function"><a href="function.mssql-connect.html" class="function">mssql_connect()</a></span> was called, and use it.
      </p>
     </dd>

    
   </dl>

  </p>
 </div>


 <div class="refsect1 returnvalues" id="refsect1-function.mssql-select-db-returnvalues">
  <h3 class="title">返回值</h3>
  <p class="para">
   成功时返回 <strong><code>TRUE</code></strong>， 或者在失败时返回 <strong><code>FALSE</code></strong>。
  </p>
 </div>


 <div class="refsect1 examples" id="refsect1-function.mssql-select-db-examples">
  <h3 class="title">范例</h3>
  <p class="para">
   <div class="example" id="mssql.mssql-select-db.example.basic">
    <p><strong>Example #1 <span class="function"><strong>mssql_select_db()</strong></span> example</strong></p>
    <div class="example-contents">
<div class="phpcode"><code><span style="color: #000000">
<span style="color: #0000BB">&lt;?php<br /></span><span style="color: #FF8000">//&nbsp;Create&nbsp;a&nbsp;link&nbsp;to&nbsp;MSSQL<br /></span><span style="color: #0000BB">$link&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">mssql_connect</span><span style="color: #007700">(</span><span style="color: #DD0000">'KALLESPC\SQLEXPRESS'</span><span style="color: #007700">,&nbsp;</span><span style="color: #DD0000">'sa'</span><span style="color: #007700">,&nbsp;</span><span style="color: #DD0000">'phpfi'</span><span style="color: #007700">);<br /><br /></span><span style="color: #FF8000">//&nbsp;Select&nbsp;the&nbsp;database&nbsp;'php'<br /></span><span style="color: #0000BB">mssql_select_db</span><span style="color: #007700">(</span><span style="color: #DD0000">'php'</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">$link</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">?&gt;</span>
</span>
</code></div>
    </div>

   </div>
  </p>
  <p class="para">
   <div class="example" id="mssql.mssql-select-db.example.escape">
    <p><strong>Example #2 Escaping the database name with square brackets</strong></p>
    <div class="example-contents">
<div class="phpcode"><code><span style="color: #000000">
<span style="color: #0000BB">&lt;?php<br /></span><span style="color: #FF8000">//&nbsp;Create&nbsp;a&nbsp;link&nbsp;to&nbsp;MSSQL<br /></span><span style="color: #0000BB">$link&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">mssql_connect</span><span style="color: #007700">(</span><span style="color: #DD0000">'KALLESPC\SQLEXPRESS'</span><span style="color: #007700">,&nbsp;</span><span style="color: #DD0000">'sa'</span><span style="color: #007700">,&nbsp;</span><span style="color: #DD0000">'phpfi'</span><span style="color: #007700">);<br /><br /></span><span style="color: #FF8000">//&nbsp;Select&nbsp;the&nbsp;database&nbsp;'my.database-name'<br /></span><span style="color: #0000BB">mssql_select_db</span><span style="color: #007700">(</span><span style="color: #DD0000">'[my.database-name]'</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">$link</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">?&gt;</span>
</span>
</code></div>
    </div>

   </div>
  </p>
 </div>


 <div class="refsect1 seealso" id="refsect1-function.mssql-select-db-seealso">
  <h3 class="title">参见</h3>
  <p class="para">
   <ul class="simplelist">
    <li class="member"><span class="function"><a href="function.mssql-connect.html" class="function" rel="rdfs-seeAlso">mssql_connect()</a> - Open MS SQL server connection</span></li>
    <li class="member"><span class="function"><a href="function.mssql-pconnect.html" class="function" rel="rdfs-seeAlso">mssql_pconnect()</a> - Open persistent MS SQL connection</span></li>
    <li class="member"><span class="function"><a href="function.mssql-query.html" class="function" rel="rdfs-seeAlso">mssql_query()</a> - Send MS SQL query</span></li>
   </ul>
  </p>
 </div>


</div><hr /><div class="manualnavbar" style="text-align: center;">
 <div class="prev" style="text-align: left; float: left;"><a href="function.mssql-rows-affected.html">mssql_rows_affected</a></div>
 <div class="next" style="text-align: right; float: right;"><a href="set.mysqlinfo.html">MySQL</a></div>
 <div class="up"><a href="ref.mssql.html">Mssql 函数</a></div>
 <div class="home"><a href="index.html">PHP Manual</a></div>
</div></body></html>
